/*
 * pn_lld.h
 *
 *  Created on: 09.05.2013
 *      Author: Roma Jam
 */

#ifndef PN_LLD_H_
#define PN_LLD_H_

#include "kl_lib_l15x.h"
#include "spi_sw.h"
#include "pn_defins.h"

// TimeOuts
#define CMD_TIMEOUT                 45
#define DATA_TIMEOUT                450

enum Pn_PktRslt_t {pnPktACK, pnPktErrFrame, pnPktOk, pnPktFail, pnPktCRC, pnPktCmdWrongCode, pnPktCmdErrorCode };


class Pn_lvl1_t {
private:
//	uint8_t Buf[45];
//	uint32_t PktLen;

	Pn_PktRslt_t WriteAndWaitData(uint8_t *PBuf2, uint32_t ALen2, uint8_t *POutBuf, uint32_t *POutLen);
	Pn_PktRslt_t WriteAndWaitReply(uint8_t *PBuf2, uint32_t ALen2, uint8_t *POutBuf, uint32_t *POutLen);
	void WritePkt(uint8_t *PDataBuf, uint32_t ADataLen);

public:
	uint8_t Buf[45];
	uint32_t PktLen;
	bool Reply_Is_Ready()	{return (!Irq.isHi()); }
	Pn_PktRslt_t Cmd(uint8_t ACmd, uint16_t ALength, ...);
	Ports_t Rst, Irq;
	void Init();

	// Inner use
	Pn_PktRslt_t ReadPkt(uint8_t *PDataBuf, uint32_t *RLen);
};

extern Pn_lvl1_t Pn_lvl1;

#endif /* PN_LLD_H_ */
